package abd.pr1.Interface;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.util.Date;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.toedter.calendar.JDateChooser;

public class AdminUserPanel extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JLabel nick;
	private JLabel passLabel;
	private JTextField pass;
	private JLabel imagenLabel;
	private JFileChooser imagenFile = new JFileChooser();
	private JLabel nacimientoLabel;
	private JDateChooser nacimiento;
	private JButton fileselectionbutton;
	private JButton guardar;
	private JButton cerrar;
	public AdminUserPanel() {

		super();
		this.build();
		
		this.setSize(400,500);
		this.setLocationRelativeTo(null);
		this.setVisible(true);
		

	}

	private void build() {

		this.setLayout(new BorderLayout());

		JPanel fotoPanel = new JPanel();
		JPanel datosPanel = new JPanel(new GridLayout(5,1));
		JPanel botones = new JPanel();
		nick = new JLabel();
		
		passLabel = new JLabel("Contraseña:");
		pass = new JTextField();
		
		imagenLabel=new JLabel();
		imagenLabel.setSize(100, 100);
		
		fileselectionbutton = new JButton("Seleccionar avatar");
		fileselectionbutton.setActionCommand("seleccion_avatar");
		
		nacimientoLabel = new JLabel();
		nacimiento=new JDateChooser();
		
		guardar=new JButton("Guardar");
		guardar.setActionCommand("guardar_user");
		
		cerrar=new JButton("Cerrar");
		cerrar.setActionCommand("cerrar_user");
		
		fotoPanel.add(imagenLabel);
		fotoPanel.add(fileselectionbutton);
		
		datosPanel.add(nick);
		datosPanel.add(passLabel);
		datosPanel.add(pass);
		datosPanel.add(nacimientoLabel);
		datosPanel.add(nacimiento);
		
		botones.add(guardar);
		botones.add(cerrar);
		
		this.add(fotoPanel, BorderLayout.NORTH);
		this.add(datosPanel, BorderLayout.CENTER);
		this.add(botones, BorderLayout.SOUTH);
	}

	public void setNick(String nickuser) {
		this.nick.setText(nickuser);
	}

	public void setEdad(Date edad) {
	
		this.nacimiento.setDate(edad);
	}
	
	public void setImagen(ImageIcon imagen){

		imagen=new ImageIcon(imagen.getImage().getScaledInstance(100, 100,  java.awt.Image.SCALE_SMOOTH));
		imagenLabel.setIcon(imagen);
		
	}
	
	public String getPassword(){
		return pass.getText();
	}
	
	public Date getNacimiento(){
		return nacimiento.getDate();
	}

	public JFileChooser getFileChooser() {
		return this.imagenFile;		
	}

	public void setPassword(String password) {
		this.pass.setText(password);		
	}
	
	public void addListener(ActionListener a){
		imagenFile.addActionListener(a);
		fileselectionbutton.addActionListener(a);
		guardar.addActionListener(a);
		cerrar.addActionListener(a);
	}
	
}
